package com.walk.zworld.ui.fragment.video

import android.view.View
import android.widget.ImageView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.walk.zworld.R
import com.walk.zworld.square.load
import com.walk.zworld.ui.activity.YouDetailVideoActivity
import com.walk.zworld.ui.fragment.video.model.DtDetailModel
import com.walk.zworld.utils.GlobalUtil
import com.base.lib.base.BaseApplication
import com.base.lib.base.adapter.BaseSkeletonAdapter
import com.base.lib.common.utils.ScreenUtils

class YouVideoAdapter : BaseSkeletonAdapter<DtDetailModel, BaseViewHolder>(R.layout.you_dt_rv_item){
    companion object{
        val imgWidth = (ScreenUtils.getScreenWidth(BaseApplication.instance) - GlobalUtil.getDimension(R.dimen.dp_5) * 3) / 2
    }

    override fun convert(holder: BaseViewHolder, item: DtDetailModel) {
        val ivPic: ImageView = holder.getView(R.id.ivPic)
        val ivVideoTag: ImageView = holder.getView(R.id.ivVideoTag)
        val ivZan: ImageView = holder.getView(R.id.ivZan)
        val layoutParams = ivPic.layoutParams
        if (item.width != null && item.height != null && item.width != 0 && item.height != 0) {
            layoutParams.width = imgWidth
            val scale = (imgWidth + 0f) / item.width!!
            var h = (item.height!! * scale).toInt()
            if (h < GlobalUtil.getDimension(R.dimen.dp_120)) {
                h = GlobalUtil.getDimension(R.dimen.dp_120)
            }
            layoutParams.height = h
            ivPic.layoutParams = layoutParams
            ivPic.load(item.poster)
        } else {
            layoutParams.width = imgWidth
            layoutParams.height = GlobalUtil.getDimension(R.dimen.dp_200)
            ivPic.layoutParams = layoutParams
            ivPic.load(item.poster)
        }

        val ivUserHead: ImageView = holder.getView(R.id.ivUserHead)
        ivUserHead.load(item.createUserPic)

        ivVideoTag.visibility = if (item.videoType == 1) View.VISIBLE else View.GONE
        holder.setText(R.id.tvTitle, item.videoName)
        holder.setText(R.id.tvUsername, item.createUsername)
        holder.setText(R.id.tvZanCount, item.dianzanCount.toString() + "")
        if (item.myDianzanCount == 1) {
            ivZan.setImageResource(R.mipmap.ic_like)
        } else {
            ivZan.setImageResource(R.mipmap.ic_not_like)
        }
        holder.itemView.setOnClickListener {
//            if (ClickHelper.isFastDoubleClick()) {
//                return@OnClickListener
//            }
            if (item.videoType == 1) {
                YouDetailVideoActivity.start(context, item.id)
            } else if (item.videoType == 0) {
//                DtDetailPicActivity.launch(context, item.id)
            }
        }
    }
}